import { Component, ViewChild,OnInit } from '@angular/core';
// import { NavController } from 'ionic-angular';
import { HomeService } from './service';
import { Shop } from './model/shop-model';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage implements OnInit{

  public shop: Shop = new Shop();
  public tagList = [{
    name:'附近',
    active:false
  },{
    name:'商家',
    active:false
  },{
    name:'折扣',
    active:false
  },{
    name:'共享金额',
    active:false
  }];

  constructor(public homeService: HomeService) {
  }

  ngOnInit(): void {
    this.fetchRandomData();
    // this.getShopList();
  }

  //解决切换其他页面回去轮播图不动问题
  ionViewWillEnter() {
  }
  ionViewWillLeave() {
  }

  public getShopList(){
    this.homeService
      .getShopList()
      .subscribe(
        data => {
          console.log(data);
          this.shop = data
        },
        error => console.error(error)
      );
  }

  public fetchRandomData() {
    this.homeService
      .fetchRandomData({})
      .subscribe(
        data => console.log(data),
        error => console.error(error)
      );
  }

  tagChose(list:any){
    list.active = !list.active;
  }

  doRefresh(refresher){
    setTimeout(() => {
      console.log('Async operation has ended');
      refresher.complete();
    }, 2000);
  }
}
